package cn.aylog.real;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

public class MyRealm extends AuthorizingRealm {

    // 身份信息
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        String username = token.getPrincipal().toString();
        String password = new String((char[]) token.getCredentials());
        System.out.println("用户输入:" + username + "---" + password);
        if("zhangsan".equals(username)) {
            String pwd = "zs"; // 正确的密码与用户输入的密码进行验证
            System.out.println("正确:zhangsan---zs");
            AuthenticationInfo info = new SimpleAuthenticationInfo(username, pwd, "realmName");
            return info;
        }
        return null;
    }

    // 授权信息
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection token) {
        AuthorizationInfo info = new SimpleAuthorizationInfo();
        return info;
    }
}
